$scope.ToPrint = function (x) {
    var LODOP = getLodop();
    var Pid = x.Pid;//根据pid获取信息
    var PrintTemplateName = "";//模板名称
    var PtDocument = "";//模板内容
    $scope.GoodsWeight = 0;//商品的总重
    $scope.GoodsValue = 0;//商品的总值
    var GoodsQuantity = 0;//商品的总个数
    var GoodsName = "";//商品的总名称
    //获取商品信息
    $http.post('../api/GetItemRecordsByPid', { Language_Type: 1, Pid: Pid }).then(function (res) {
        $scope.MoreGoods = res.data;
        angular.forEach(res.data, function (ags, index, array) {//data等价于array[index]
            //alert(array[index].Item_unit_price);
            //alert(ags.Item_unit_price + '=' + array[index].Item_unit_price);
            $scope.GoodsValue += (array[index].Item_unit_price) * (array[index].Item_quantity);
            $scope.GoodsWeight += (array[index].Item_weight) * (array[index].Item_quantity);
            GoodsQuantity += array[index].Item_quantity;
            GoodsName += array[index].Item_name;
        });
        $http.post('../api/GetPrintRecordsByPid', { Pid: Pid, Language_Type: 1 }).then(function (response) {
            $scope.Currency = response.data[0].Currency;//币种
            $http.post('../api/GetPrintRecordsByPid', { Pid: Pid, Language_Type: 1 }).then(function (response) {
                $scope.Pid = response.data[0].Pid;
                //订单表
                $scope.Pid = response.data[0].Pid;
                var OrderNo = response.data[0].Order_No;//订单号
                var Weight = response.data[0].Weight;//包裹重量
                var TotalItemPrice = response.data[0].Total_Item_Price;//包裹价格
                var RemarkOrder = response.data[0].RemarkOrder;//备注
                var NoDeliver = response.data[0].No_Deliver;//不能被投递时的策略
                var Currency = response.data[0].Currency;//币种
                var CustomerAllName = response.data[0].Customer_All_Name;
                var InterMailNo = response.data[0].Inter_Mail_No;//国际物流运单号
                var MailNo = response.data[0].Mail_No;//运单号
                var ShipType = response.data[0].Ship_Type;//运输方式
                var MailType = response.data[0].Mail_Type;//邮件种类
                var PickupContact = response.data[0].Pickup_Contact;//上门揽收地址
                var PackageCode = response.data[0].Package_Code;//包裹代码

                //商品表
                var ItemName = response.data[0].Item_name;//商品名称
                var ItemUnitPrice = response.data[0].Item_unit_price;//商品单价 单位为分
                var ItemWeight = response.data[0].Item_weight;//商品单重
                var ItemQuantity = response.data[0].Item_quantity;//商品个数
                //发货人信息表
                var SenderCode = response.data[0].Sender_Code;//发货人编号
                var SenderName = response.data[0].Sender_Name;
                var SenderMobile = response.data[0].Sender_Mobile;//发货人手机号
                var SenderPhone = response.data[0].Sender_Phone;
                var SenderZipCode = response.data[0].Sender_Zip_Code;//发货邮编
                var SenderCity = response.data[0].Sender_City;//市
                var SenderCompanyName = response.data[0].Sender_Company_Name;
                var SenderAddress = (response.data[0].Sender_Country) + (response.data[0].Sender_Province) + (response.data[0].Sender_City) + (response.data[0].Sender_District) + (response.data[0].Sender_Street_Address);
                //收件人信息表
                var ReceiverName = response.data[0].Name;
                var ReceiverMobile = response.data[0].Mobile;//手机号
                var ReceiverPhone = response.data[0].Phone;
                var ReceiverZipCode = response.data[0].Zip_Code;//发货邮编
                var ReceiverCity = response.data[0].City;
                var ReceiverCompanyName = response.data[0].Receiver_Company_Name;
                var ReceiverAddress = (response.data[0].Country) + (response.data[0].Province) + (response.data[0].City) + (response.data[0].District) + (response.data[0].Street_Address);
                //运单表
                var WeightFee = response.data[0].Weight_Fee;//计费重量
                var SendContact = response.data[0].Send_Contact;//发件人
                var SendContactAddress = response.data[0].Send_Contact_Address;//发货地址
                var ReceiveContact = response.data[0].Receive_Contact;//收货人
                var ReceiveContactAddress = response.data[0].Receive_Contact_Address;//收货地址

                //根据运输方式查询业务配置表里模板
                $http.post('../api/GetCONFIGUREByValue', {TST_NAME: ShipType }).then(function (response) {
                    if (response.data != null) {
                        PrintTemplateName = response.data[0].PRINT_TEMPLATE;//面单模板名称
                        //alert(response.data[0].PRINT_TEMPLATE);
                    }
                });
                //根据模板名称获取模板内容
                $http.post('../api/loadPrint', { Pt_Name: PrintTemplateName }).then(function (response) {
                    if (response.data != null) {
                        PtDocument = response.data[0].Pt_Document;//面单模板内容
                        //alert(response.data[0].Pt_Document);
                        //LODOP.PREVIEW();
                    }
                });


                //if (LODOP.CVERSION) CLODOP.On_Return = function (TaskID, Value) {
                //    PtDocument.value = Value;};
                //重新运算求出参数的内容
                //eval(PtDocument);
                //if (LODOP.CVERSION) CLODOP.On_Return = null;
                //LODOP.PREVIEW(PtDocument);
                ////先预览在打印
                LODOP.PREVIEW();
            });

        })
    });

}